/*
============================================================================
FileName	:	XQChatRosterManager.h
Author		:	liyake
Website		:	http://www.liyake.com
Create Data	:	2012-03-15 10:43
Change Data	:	2012-03-15 10:43
Detail		:	roster manager.
============================================================================
*/

#ifndef _XQCHAT_ROSTER_MANAGER_H_
#define _XQCHAT_ROSTER_MANAGER_H_
#include "XQChatRoster.h"

namespace XQChat
{
	class CXQChatRosterManager : public QObject
	{
		Q_OBJECT
	public:
		CXQChatRosterManager(QObject* parent = 0);
		~CXQChatRosterManager(void);

	public:
		static CXQChatRosterManager* getRosterManager();

	public:
		void ClearRosters();
		CXQChatRoster* getRosterByFullJid(const QString& jid);
		CXQChatRoster* getRosterByNick(const QString& nick);
		QList<CXQChatRoster*> getRostersByBareJid(const QString& jid);
		QList<CXQChatRoster*> getRostersByMemType(uint type);
		QList<CXQChatRoster*> getRostersAll();

		QString getHeadersPath() const { return m_qsHeadersPath; }

		/*add a roster to the map. 
		  if there already had a same roster, return false.
		*/
		bool addRoster(CXQChatRoster* pRoster);
		bool removeRoster(const QString& qsBareJid);

		bool addBlocked(const QString& jid);

		void updateNick(const QString& bareJid, const QString& nick)
		{
			m_mapNicks[bareJid] = nick;
			saveNicks();
		}

	private:
		void loadNicks();
		void saveNicks();

	private:
		QMap<QString,CXQChatRoster*> m_mapRosters;	//QString:roster's jid + client type.
		QString m_qsHeadersPath;

		static CXQChatRosterManager* m_pRosterManager;

		QMap<QString,QString> m_mapNicks;

		QList<QString> m_listBlocked;
	};
}

#endif	//_XQCHAT_ROSTER_MANAGER_H_